using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WozLib.UI.Util;

namespace WozLib.UI.Controls
{
  /// <summary>
  /// Interaction logic for ColorSlider.xaml
  /// </summary>

  public partial class ColorSlider : Slider
  {
    public ColorSlider()
    {
      InitializeComponent();
      this.Loaded += new RoutedEventHandler(ColorSlider_Loaded);
    }

    private void ColorSlider_Loaded(object sender, RoutedEventArgs e)
    {
      LinearGradientBrush b;

      b = new LinearGradientBrush();
      b.StartPoint = new System.Windows.Point(0, 0);
      b.EndPoint = new System.Windows.Point(0, 1);

      // not sure if this is supposed to be < or <=
      for (int i = 0; i < 9; i++)
      {
        b.GradientStops.Add(new GradientStop(HlsConverter.ConvertFromHls(i / 9.0, 0.5, 1), 1 - i / 9.0));
      }

      this.Background = b;
    }

    void ColorSlider_MouseDown(object sender, MouseButtonEventArgs e)
    {
      System.Windows.Point point;
      FrameworkElement host;

      host = sender as System.Windows.FrameworkElement;
      point = System.Windows.Input.Mouse.GetPosition(host);

      this.Value = (host.ActualHeight - point.Y) / host.ActualHeight;
    }

  }
}